<%@page import="cn.yi.newsys.service.impl.UserServiceImpl"%>
<%@page import="cn.yi.newsys.service.UserService"%>
<%@page import="cn.yi.newsys.pojo.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'UserAdd.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    	request.setCharacterEncoding("UTF-8") ;
    	// 用户名
       	String userName = request.getParameter("userName") ;
        // 密码
        String userPass = request.getParameter("userPass") ;
        // 确认密码
        String rePass = request.getParameter("rePass") ;
        // 用户类型
        Integer userType = Integer.valueOf(request.getParameter("userType")) ;
        	
        // 创建用户业务逻辑对象
        UserService us = new UserServiceImpl() ;
        
        // 创建 User 对象
		User user = new User(userName,userPass,userType,null) ;
		int temp = us.registerUser(user) ;
		if(temp == 1){
			out.println("<script>alert('保存成功！');location.href='../manage/index.jsp';</script>") ;
		}else if(temp == 0){
			out.println("<script>alert('出现未知故障，保存失败！');location.href='../manage/index.jsp';</script>") ;
		}else{
			out.println("<script>alert('用户名已存在，请重新输入！');location.href='../manage/index.jsp';</script>") ;
		}
    %>
  </body>
</html>
